package com.zhima.function;

import com.zhima.panel.NewLineConfiguration;
import com.zhima.panel.RandomInDataConfiguration;

import java.util.Set;
import java.util.function.Consumer;

public class ConfigurationIndexAssociate implements Consumer<RandomInDataConfiguration> {
    private final Set<Integer> randomInDataConfigurationIndexCanBeAssociated;

    public Set<Integer> getRandomInDataConfigurationIndexCanBeAssociated() {
        return randomInDataConfigurationIndexCanBeAssociated;
    }

    public ConfigurationIndexAssociate(Set<Integer> randomInDataConfigurationIndexCanBeAssociated) {
        this.randomInDataConfigurationIndexCanBeAssociated = randomInDataConfigurationIndexCanBeAssociated;
    }

    @Override
    public void accept(RandomInDataConfiguration randomInDataConfiguration) {
        if (randomInDataConfiguration.getClass() == NewLineConfiguration.class) {
            return;
        }
        if (!randomInDataConfiguration.isArray() && !randomInDataConfiguration.isBoolean()) {
            randomInDataConfigurationIndexCanBeAssociated.add(randomInDataConfiguration.getRowIndex() + 1);
        } else {
            randomInDataConfigurationIndexCanBeAssociated.remove(randomInDataConfiguration.getRowIndex() + 1);
        }
    }
}
